<div class="row">
	<div class="col-md-12">
		<form id="edit-form" class="form-horizontal" action="${request.contextPath}/oms/ucenter/permission/update" method="post" onsubmit="return false">
			<input type="hidden" id="id" name="id" value="${permissionInit.id}">
			<div class="box-body" >
				<div class="form-group">
					<label for="permission-code" class="col-sm-2 control-label" >编码</label>
					<div class="col-sm-4">
						<input type="text" class="form-control" name="code" id="permission-code"  value="${permissionInit.code}" placeholder="输入编码...">
					</div>
				</div>
				<div class="form-group">
					<label for="permission-url" class="col-sm-2 control-label">URL路径</label>
					<div class="col-sm-10">
						<input type="text" class="form-control" name="url" id="permission-url" value="${permissionInit.url}" placeholder="输入URL路径...">
					</div>
				</div>
				<div class="form-group">
					<label for="permission-permissionInit" class="col-sm-2 control-label">权限</label>
					<div class="col-sm-10">
						<input  type="text" id="permission-permissionInit" class="form-control color-input" name="permissionInit"   value="${permissionInit.permissionInit}" placeholder="请输入权限...">
					</div>
				</div>

				<div class="form-group">
					<label  for="permission-sort-order" class="col-sm-2  control-label">排列顺序</label>
					<div class="col-sm-4">
						<input  type="number" id="permission-sort-order" class="form-control color-input" name="sortOrder" value="${permissionInit.sortOrder}"  placeholder="选择排列顺序...">
					</div>
					<label  for="permission-status" class="col-sm-2  control-label">状态</label>
					<div class="col-sm-4">
						<select class="form-control" id="permission-status"  name="status" style="width: 100%;">
						</select>
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-2 control-label" >描述</label>
					<div class="col-sm-10">
						<input type="text" class="form-control" name="description" id="permission-description" value="${permissionInit.description}" placeholder="输入描述...">
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-2 control-label">备注</label>
					<div class="col-sm-10">
						<input type="text" class="form-control" name="remark" id="permission-remark"  value="${permissionInit.remark}"  placeholder="输入备注...">
					</div>
				</div>
				<div class="error-message text-center" id="addFormErrorMsgContainer">
					<span class="error-icon"></span>
					<span id="addFormErrorMsg" class="error-msg" ></span>
				</div>
			</div>
			<div class="box-footer">
				<div class="pull-right">
               		<button type="submit" class="btn btn-primary btn-sm"><i class="fa fa-paste"></i> 更新</button>
               		<button type="button" class="btn btn-default btn-sm" data-dismiss="modal"><i class="fa fa-close"></i> 关闭</button>
				</div>
          	</div>
		</form>
	</div>
</div>
<script type="text/javascript">
function ajaxSubmit(form) {
	var $form = $(form);
	if ($form.length === 1 && $form.validate()) {
        $.ajax({
            type: 'post',
            url: form.action,
            dataType: "json",
            data: $form.serialize()
        }).done(function(result){
            if (result.success) {
                $("#lgModal").modal('hide');
                alertMsg(result.message,"success");
                dataGridReload();
            } else {
                $form.find(".error-msg").show();
                $form.find(".error-msg").html(result.message);
            }
        });
	}
}

$(function() {

    $("#permission-status").select2({
        data: StatusStore,
        placeholder: "请选择...",
        language: "zh-CN",
        theme: "bootstrap",
        minimumResultsForSearch: Infinity
    }).val('${permissionInit.status}').trigger("change");

	var $editForm = $("#edit-form");
	$editForm.validate({
        rules: {
            code: {
                required: true
            },
            url: {
                required: true
            },
            permissionInit: {
                required: true
            }
        },
        messages: {
            code:{
                required:"编码不能为空！"
            },url:{
                required:"URL路径不能为空！"
            },permissionInit:{
                required:"权限不能为空！"
            }
        },
		submitHandler:ajaxSubmit,
		errorLabelContainer:".error-msg",
		wrapper:"li",
		showErrors:function(errorMap,errorList) {
			if(errorList.length>0){
				$editForm.find(".error-msg").html(errorList[0].message);
			}else{
				$editForm.find(".error-msg").html("");
			}
		},
		onkeyup: false
	});
});
</script>